7 days with Binary Tree by Kiao Ue & Chatterjee Aditya

7 days with Binary Tree by Kiao Ue & Chatterjee Aditya

Author:Kiao, Ue & Chatterjee, Aditya
Language: eng
Format: epub, pdf
Publisher: OpenGenus
Published: 2021-06-05T16:00:00+00:00


Implementation:

There are 4 key steps that we take care of :

If the root==target then return all nodes in the subtree at distance k.

If the target lies in left subtree of node at distance 'm', then we will find the nodes at distance k-m in right branch.

In similar fashion we move forward with right branch of node.

If we cannot find target in either branch of the tree, then we will stop.

Pseudocode:

void percolate(root, k)

{

​if(root==NULL || k<0)

​​return ;

​

​if(k==0)

​{

​​print( root->data );

​​return;

​}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.